/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package h2x;

import elaborate.h2x.parser.TransformingModelParserBuilder;
import elaborate.h2x.parser.TransformingModelParserBuilderFactory;
import elaborate.h2x.transform.DefaultTransformerImpl;
import elaborate.h2x.transform.Transformer;
import elaborate.h2x.transform.TransformingModel;
import java.io.File;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import juixb.schema.SchemaModel;
import juixb.schema.SchemaModelBuilder;
import juixb.schema.xsd.xmlbeans.XmlBeansSchemaModelBuilderFactory;
import org.w3c.dom.Document;

/**
 *
 * @author lendle
 */
public class Test3 {
    public static void main(String [] args) throws Exception{
        /*XmlBeansSchemaModelBuilderFactory factory=new XmlBeansSchemaModelBuilderFactory(new File("src\\books.xsd").toURI().toURL(), true, false);
        SchemaModelBuilder schemaModelBuilder=factory.newSchemaModelBuilder();
        SchemaModel schemaModel=schemaModelBuilder.buildSchemaModel(new QName("test1", "books"));
        System.out.println(schemaModel.getRootNode().children().nextElement());
        */
        TransformingModelParserBuilderFactory tmf=TransformingModelParserBuilderFactory.newInstance();
        TransformingModelParserBuilder tmb=tmf.newTransformingModelParserBuilder();

        DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db=dbf.newDocumentBuilder();
        Document doc=db.parse(new File("src\\example4.xhtml"));

        TransformingModel model=tmb.newTransformingModelParser().parse(doc);

        Transformer transformer=new DefaultTransformerImpl();
        List<Document> newDocs=transformer.transform(model);

        javax.xml.transform.Transformer tf=TransformerFactory.newInstance().newTransformer();
        for(Document newDoc : newDocs){
            tf.transform(new DOMSource(newDoc), new StreamResult(System.out));
        }
    }
}
